<?php

namespace App\Http\Queries;

use App\Models\CustomerInfo;
use Spatie\QueryBuilder\QueryBuilder;
use Spatie\QueryBuilder\AllowedFilter;

class CustomerInfoQuery extends QueryBuilder
{
    public function __construct()
    {
        parent::__construct(CustomerInfo::query());
        $this->allowedIncludes('activity', 'vehicle', 'dealer', 'rmore', 'referee');
        $this->allowedFilters([
            'name',
            'province',
            'city',
            AllowedFilter::exact('phone'),
            AllowedFilter::exact('referee_id'),
            AllowedFilter::exact('channel'),
            AllowedFilter::exact('activity_id'),
            AllowedFilter::exact('vehicle_id'),
            AllowedFilter::exact('user_id'),
            AllowedFilter::scope('status'),
            AllowedFilter::scope('dealer_code')
        ]);
        $this->defaultSort('-id');
    }
}
